home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Libris Britannia 4
/
science library(b).zip
/
science library(b)
/
PROGRAMM
/
DB_CLIPP
/
0277.ZIP
/
WILDMSD2.C
< prev
next >
Wrap
Text File
|
1985-08-04
|
5KB
|
220 lines
/*
WILDEXP.C
C86 C version of wildexp.c - thanks to
Leor Zolman for original BDS C version.
26.08.84 - C86 version for DOS 2.xx
*/
#include <stdio.h>
#define FNSZE 80 /* maximum filename size */
#define ERROR -1
#define MAXITEMS 500 /* max no. of items after expansion */
#define SEARCH_FIRST 17 /* BDOS calls */
#define SEARCH_NEXT 18
#define TRUE 1
#define FALSE 0
struct regval { unsigned ax, bx, cx, dx, si, di, ds, es; };
struct sval { unsigned css, sss, dss, ess; };
wildexp(oargcp, oargvp, atts)
int *oargcp; /* pointer to old argc */
char ***oargvp; /* pointer to old argv */
int atts; /* desired file attributes */
{
int nargc; /* new argc */
char **nargv; /* new argv */
char **oargv; /* old argv */
int oargc; /* old argc */
int dmapos; /* value returned by search calls */
char first_time; /* used in search routine */
char tmpfn[FNSZE],*tmpfnp;
int new_c;
int i,j,k;
char c;
char *sbrk();
char cur_dir[68], root_dir[5];
char fd[FNSZE], dta[128];
char *strrchr();
struct regval regs;
struct sval segs;
/* structure of fileblock for DOS 2.x search/first/next */
struct dta2 {
char dosres[21]; /* reserved by DOS */
char att2; /* file attribute */
int ft2; /* file time */
int fd2; /* file date */
long fs2; /* file size */
};
struct dta2 *dtaptr;
/*
-------------------------------------------------
structure of file info block from wildexp modules
-------------------------------------------------
*/
struct fil_info {
unsigned attrib; /* attribute found (int for future UNIX) */
unsigned ftime; /* file time MSDOS format */
unsigned fdate; /* file date MSDOS format */
long fsize; /* file size */
char fil_nam[FNSZE]; /* ASCIIZ file name - maximum which is not all allocated by sbrk */
};
struct fil_info *finfo;
/* get current(default) drive/directory */
segread(&segs);
regs.ds = segs.dss;
cur_dir[0] = bdos(25,0) + 65; /* get default drive */
cur_dir[1] = '\0';
strcat(cur_dir,":\\");
strcpy(root_dir,cur_dir);
regs.si = (unsigned) &cur_dir[3]; /* only for small model */
regs.dx = 0;
regs.bx = 0;
regs.ax = 0x4700;
sysint21(®s, ®s);
if(strlen(cur_dir) > 3)
strcat(cur_dir,"\\");
bdos(26,dta); /* set DTA */
oargv = *oargvp;
oargc = *oargcp;
nargc = 1;
if ((nargv = (char **) sbrk(MAXITEMS * 2 + 2)) == (char *) -1)
return ERROR;
dtaptr = (struct dta2 *) &dta[0];
if((new_c = oargc) == 1)
new_c++;
for (i = 1; i < new_c; i++)
{
if(oargc != 1)
{
j =0;
while(( c = oargv[i][j]) != '\0')
fd[j++] = ( c == '/') ? '\\' : c;
fd[j] = '\0';
}
else
strcpy(fd,"*.*");
if(strcmp(fd,"\\") == 0)
strcpy(fd, root_dir);
if(strrchr(fd,'\\') == NULL && fd[1] == ':')
{
strncpy(tmpfn,fd,2);
tmpfn[2] = '\0';
strcat(tmpfn,"\\");
if(strlen(fd) == 2)
strcat(tmpfn, "*.*");
else
strcat(tmpfn, &fd[2]);
}
else if(strrchr(fd,'\\') == NULL && fd[1] != ':')
{
strcpy(tmpfn,cur_dir);
strcat(tmpfn,fd);
}
else
strcpy(tmpfn, fd);
if(strlen(tmpfn) == 3 && tmpfn[1] == ':' && tmpfn[2] == '\\')
strcat(tmpfn,"*.*");
tmpfnp = strrchr(tmpfn, '\\') + 1;
strcpy(fd,tmpfn);
first_time = TRUE;
while (1) /* find all matching files */
{
bdos(26,dta); /* set DTA */
dmapos = (first_time) ? srchfst(fd, atts) : srchnxt();
if (dmapos == -1)
break;
if(first_time && (dtaptr->att2 & 0x10) && strrchr(fd,'*') == NULL && strrchr(fd,'?') == NULL)
{
strcat(fd,"\\");
strcat(fd,"*.*");
strcpy(tmpfn, fd);
tmpfnp = strrchr(tmpfn,'\\') + 1;
continue;
}
first_time = FALSE;
hknam2(tmpfnp,dta);
if ((nargv[nargc] = sbrk((sizeof(struct fil_info)-FNSZE)+strlen(tmpfn) + 1)) == (char *) -1)
return ERROR;
finfo = (struct fil_info *) nargv[nargc];
strcpy(finfo->fil_nam,tmpfn);
finfo->attrib = dtaptr->att2;
finfo->ftime = dtaptr->ft2;
finfo->fdate = dtaptr->fd2;
finfo->fsize = dtaptr->fs2;
nargc++;
}
}
*oargcp = nargc;
*oargvp = nargv;
return 0;
}
hknam2(dest,source)
char *dest, *source;
{
int i,j,k;
j = 0;
for (i = 30; i < 45; i++)
{
if (source[i] == '\0') break;
dest[j++] = source[i];
}
dest[j] = '\0';
}
srchfst(fdesc, attributes)
char *fdesc;
int attributes;
{
struct regval regs;
struct sval segs;
int status;
segread(&segs);
regs.ds = segs.dss;
regs.ax = 0x4e00;
regs.bx = 0;
regs.cx = attributes & 0x17; /* mask out naughty bits */
regs.dx = (unsigned) fdesc;
status = sysint21(®s, ®s);
if(regs.ax == 2 || regs.ax == 18)
return(-1);
else
return(0);
}
srchnxt()
{
struct regval regs;
int status;
regs.ax = 0x4f00;
regs.bx =0;
regs.cx = 0;
regs.dx = 0;
status = sysint21(®s, ®s);
if(regs.ax == 18 || regs.ax == 2)
return(-1);
else
return(0);
}